home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
utils
/
whichsrc.arc
/
WHICH.C
< prev
Wrap
C/C++ Source or Header
|
1990-03-20
|
2KB
|
84 lines
#define DELIMETER ','
#include <stdio.h>
char *getenv();
char *index();
int
main(ac,av)
char **av;
{
char *path, *cp;
char buf[200];
char prog[200];
char patbuf[512];
int quit, none;
if (ac < 2) {
fprintf(stderr, "Usage: %s cmd [cmd, ..]\n", *av);
exit(1);
}
av[ac] = 0;
for(av++ ; *av; av++) {
quit = 0;
none = 1;
if ((path = getenv("PATH")) == NULL) {
fprintf(stderr, "Null path.\n");
exit(0);
}
strcpy(patbuf, path);
path = patbuf;
cp = path;
while(1) {
cp = index(path, DELIMETER);
if (cp == NULL)
quit++;
else
*cp = '\0';
if (strcmp(path,"") == (char *)NULL && quit == 0) {
sprintf(buf, "%s.\\%s", path, *av);
} else
sprintf(buf, "%s\\%s", path, *av);
/* fprintf(stderr,"Trying %s, path %s\n",buf,path); */
path = ++cp;
if (access(buf, 1) == 0) {
printf("%s\n", buf);
none = 0;
}
sprintf(prog, "%s.%s", buf, "prg");
if (access(prog, 1) == 0) {
printf("%s\n", prog);
none = 0;
}
sprintf(prog, "%s.%s", buf, "ttp");
if (access(prog, 1) == 0) {
printf("%s\n", prog);
none = 0;
}
sprintf(prog, "%s.%s", buf, "tos");
if (access(prog, 1) == 0) {
printf("%s\n", prog);
none = 0;
}
if (quit) {
if (none)
printf("No %s in %s\n", *av, getenv("PATH"));
break;
}
}
}
exit(0);
}